import requests

from common.config import getconf
from tests.new_rypark_background.get_cookie import internal_token


class ParkingSentryBox:
    # =====================道口管理=====================

    def create_parking_sentry(self, env,name="自动化测试新建道口"):
        """创建道口"""
        base_url = getconf(env, "zhongtai_url")
        url = base_url + "platform-parking-server/parkingSentryBox/create"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": internal_token(env)}
        dict = {
            "name": name,
            "parkingLotId": getconf(env, "parking_lot_id"),
            "parkingGarageId": getconf(env, "parking_garage_id"),
            "location": "上海市浦东新区盛夏路169号11幢1层118A室地下负一一楼"
        }
        return requests.post(url, headers=headers, json=dict).json()

    def query_parking_sentry_list(self, env, name="", parkingLotId=-1, current=1, size=10):
        """道口列表"""
        base_url = getconf(env, "zhongtai_url")
        url = base_url + "platform-parking-server/parkingSentryBox/list/page"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": internal_token(env)}
        if parkingLotId == -1:
            parkingLotId = getconf(env, "parking_lot_id")
        dict = {
            "name": name,
            "parkingLotId": parkingLotId,
            "current": current,
            "size": size
        }
        return requests.post(url, headers=headers, json=dict).json()

    def update_parking_sentry(self, env, id):
        base_url = getconf(env, "zhongtai_url")
        url = base_url + "platform-parking-server/parkingSentryBox/update"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": internal_token(env)}
        dict = {
            "id":id,
            "name": "自动化测试新建道口",
            "parkingLotId": getconf(env, "parking_lot_id"),
            "parkingGarageId": getconf(env, "parking_garage_id"),
            "location": "上海市浦东新区盛夏路169号11幢1层118A室地下负一一楼"
        }
        return requests.post(url, headers=headers, json=dict).json()